package loads

import (
	"JVM/Jvmgo/GoToJVM/instructions/base"
	"JVM/Jvmgo/GoToJVM/runtimeData"
)

/*
	这里写的是iload系列命令，
	即将整型数据从本地变量推送到操作数栈顶的字节码命令
*/

type ILOAD struct {
	base.Index8Instruction
}
type ILOAD_0 struct {
	base.NoOperandsInstruction
}
type ILOAD_1 struct {
	base.NoOperandsInstruction
}
type ILOAD_2 struct {
	base.NoOperandsInstruction
}
type ILOAD_3 struct {
	base.NoOperandsInstruction
}

func _iload(frame *runtimeData.Frame, index uint) {
	val := frame.LocalVars().GetInt(index)
	frame.OperandStack().PushInt(val)
}

// iload指令, index 来自操作数
func (self *ILOAD) Execute(frame *runtimeData.Frame) {
	_iload(frame, uint(self.Index))
}

// 其他iload_x
func (self *ILOAD_0) Execute(frame *runtimeData.Frame) {
	_iload(frame, 0)
}
func (self *ILOAD_1) Execute(frame *runtimeData.Frame) {
	_iload(frame, 1)
}
func (self *ILOAD_2) Execute(frame *runtimeData.Frame) {
	_iload(frame, 2)
}
func (self *ILOAD_3) Execute(frame *runtimeData.Frame) {
	_iload(frame, 3)
}
